/**
 *
 * jcrt and its source-code is licensed under the LGPL.
 * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
 * When copying, adapting, or redistributing this document in keeping with the guidelines above,
 * you are required to provide proper attribution to obinary.
 * If you reproduce or distribute the document without making any substantive modifications to its content,
 * please use the following attribution line:
 *
 * Copyright 2007 Atjava.com Ltd. (http://www.atjava.com) All rights reserved.
 *
 */
package com.atjava.jcrweb.servlet;

import java.io.IOException;

import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.atjava.jcrweb.JcrWebException;
import com.atjava.jcrweb.info.DirectoryInfo;
import com.atjava.jcrweb.info.LinkInfo;
import com.atjava.jcrweb.manager.LinkManager;
/**
 * 
 * 
 * @author biggie
 * @version $Revision: 1.8 $ $Date: 2008/07/17 02:07:39 $
 */
public class LinkFlexServlet extends FlexBaseServlet {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public String process(HttpServletRequest request,
			HttpServletResponse response, Map<String, String[]> inputdata)
			throws IOException, ServletException , JcrWebException , Exception {

		String type= this.getData(inputdata, "type");
		if(type.equals("createlin")){
			return createLink(request,response,inputdata);
		}
		if(type.equals("dellin")){
			return delLink(request,response,inputdata);
		}
		return null;
	}
	private String createLink(HttpServletRequest request,
			HttpServletResponse response, Map<String, String[]> inputdata) 
			throws IOException, ServletException , JcrWebException , Exception{
		LinkManager manager = LinkManager.getInstance();
		LinkInfo info = new LinkInfo();
		
		info.setClassType(DirectoryInfo.class.getName());
		info.setName(getData(inputdata,"name"));
		info.setLinkpath(getData(inputdata,"linkpath"));
		info.setCreaterCode(getData(inputdata,"createrCode"));
		manager.createLink(info);
		return null;
	}
	private String delLink(HttpServletRequest request,
			HttpServletResponse response, Map<String, String[]> inputdata) 
			throws IOException, ServletException , JcrWebException , Exception {
		LinkManager manager = LinkManager.getInstance();
		manager.deleteLink(Integer.valueOf(getData(inputdata,"id")) );
		return null;
	}
}
